package com.litxuf.logic.member.manager;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

import com.litxuf.logic.member.dao.MemberDAO;
import com.litxuf.logic.member.dao.model.School;

public class MemberManager {
	Logger logger = Logger.getLogger(this.getClass());

	private MemberDAO dao;

	 

	public MemberDAO getDao() {
		return dao;
	}

	public void setDao(MemberDAO dao) {
		this.dao = dao;
	}

	/**
	 * 查询所有的会员 made in 2010-10-9下午03:51:15
	 * 
	 * @param curpage
	 * @param pagesize
	 * @return
	 * 
	 */
	public List findAllMember(int curpage, int pagesize, String sortrule) {

		if (StringUtils.isBlank(sortrule)) {
			sortrule = "regdatetime";
		}
		return dao.findAllMember(curpage, pagesize, sortrule);

	}

	/**
	 * 统计会员的数量 made in 2010-10-9下午03:51:29
	 * 
	 * @return
	 * 
	 */
	public int findToatlMember() {
		return dao.findToatlMember();
	}

	/**
	 * 按用户名查询 made in 2010-10-9下午04:01:23
	 * 
	 * @param name
	 * @return
	 * 
	 */
	public School findMemberByName(String name) {
		return dao.findByMemberName(name);
	}

	/**
	 * 用户前台登录 made in 2010-10-15下午02:03:46
	 * 
	 * @param name
	 * @param pwd
	 * @return
	 * 
	 */
	public School findMemberByMemberNameAndPwd(String name, String pwd) {
		if (StringUtils.isNotBlank(name) && StringUtils.isNotBlank(pwd)) {

			return dao.findByMemberNameAndPwd(name, pwd);
		}
		return null;
	}

	/**
	 * 修改用户个人信息 made in 2010-10-23下午10:52:12
	 * 
	 * @param member
	 * 
	 */

	public boolean updateMember(School member) {

		try {
//			String areacode = member.getAreacode();
//			// 存储省份的区域代码
//			if (areacode != null && areacode.equals("XXX")) {
//				member.setAreaCodeProvince("XXX");
//			}
//
//			else if (areacode != null && areacode.length() >= 2) {
//				member.setAreaCodeProvince(areacode.substring(0, 2));
//			}
			dao.updateMember(member);
			return true;
		} catch (Exception e) {
		}
		return false;
	}

	public String saveMember(School member) {
		String areacode = member.getAreacode();
		// 存储省份的区域代码
		if (areacode != null && areacode.equals("XXX")) {
			member.setAreaCodeProvince("XXX");
		}

		else if (areacode != null && areacode.length() >= 2) {
			member.setAreaCodeProvince(areacode.substring(0, 2));
		}

		return dao.saveMember(member);
	}

	
	 

	/**
	 * 学校查询 made in 2010-12-5下午01:00:01
	 * 
	 * @param schoolname
	 * @param schoolType
	 * @param schoolXingzhi
	 * @param curpage
	 * @param pagesize
	 * @return
	 * 
	 */
	public List findSchool(String schoolname, String schoolType,
			String schoolXingzhi, String areacode, int curpage, int pagesize) {
		return dao.findSchool4Admin(schoolname, schoolType, schoolXingzhi,
				areacode, curpage, pagesize);
	}

	/**
	 * 后台学校个数查询 made in 2010-12-5下午01:00:15
	 * 
	 * @param schoolname
	 * @param schoolType
	 * @param schoolXingzhi
	 * @return
	 * 
	 */
	public int findSchoolCountsInfo(String schoolname, String schoolType,
			String schoolXingzhi, String areacode) {
		return dao.findSchool4Admin(schoolname, schoolType, schoolXingzhi,
				areacode);
	}

	 

	 
	 

	/**
	 * 按ID查询学校信息 made in 2010-12-6下午03:37:12
	 * 
	 * @param memberId
	 * @return
	 * 
	 */
	public School findschoolById(int memberId) {
		return dao.findMemberByMemberId(memberId);
	}

 
}
